package maintain

import (
	"github.com/gin-gonic/gin"
	"iot-base/common/logger"
	"iot-base/common/webapi"
	"os"
	"os/exec"
	"path/filepath"
)

func initRootAPI(r *gin.RouterGroup) {
	r.POST("/maintain/sreboot", func(c *gin.Context) {
		webapi.SendOK(c)
		file, _ := exec.LookPath(os.Args[0])
		path, _ := filepath.Abs(file)
		dir := filepath.Dir(path)
		dir = dir + "/restart.sh"
		reboot := exec.Command("sudo " + dir)
		logger.SLog.Error("-----s-----reboot---------------")
		reboot.Start()
	})
	r.POST("/maintain/hreboot", func(c *gin.Context) {
		webapi.SendOK(c)
		/*
			file, _ := exec.LookPath(os.Args[0])
			path, _ := filepath.Abs(file)
			dir := filepath.Dir(path)
		*/

		reboot := exec.Command("sh", "-c", "sudo reboot")
		logger.SLog.Error("-----s-----hreboot---------------")
		reboot.Start()
	})
}
